nexus\api\rtapi/
player.rs

1use super::RealTimeData;
2use bitflags::bitflags;
3use std::ffi::CStr;
4
5#[derive(Debug, Clone)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub struct PlayerData {
8    /// Account name of current player.
9    pub account_name: String,
10
11    /// Character name of current player.
12    pub character_name: String,
13
14    /// Current position of character.
15    pub character_position: [f32; 3],
16
17    /// Current facing direction of character.
18    pub character_facing: [f32; 3],
19
20    /// Profession of character.
21    pub profession: u32,
22
23    /// Current 3rd specialization of character.
24    pub elite_specialization: u32,
25
26    /// Index of the mount, if applicable.
27    pub mount_index: u32,
28
29    /// Current state of the character.
30    pub character_state: CharacterState,
31}
32
33impl PlayerData {
34    /// Reads player data from the given data pointer.
35    ///
36    /// # Safety
37    /// The pointer must be safe to read from.
38    pub unsafe fn read(data: *const RealTimeData) -> Self {
39        Self {
40            account_name: CStr::from_ptr((*data).account_name.as_ptr())
41                .to_string_lossy()
42                .into_owned(),
43            character_name: CStr::from_ptr((*data).account_name.as_ptr())
44                .to_string_lossy()
45                .into_owned(),
46            character_position: (*data).character_position,
47            character_facing: (*data).character_facing,
48            profession: (*data).profession,
49            elite_specialization: (*data).elite_specialization,
50            mount_index: (*data).mount_index,
51            character_state: CharacterState::from_bits_retain((*data).character_state),
52        }
53    }
54}
55
56bitflags! {
57    #[derive(
58        Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
59    )]
60    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61    pub struct CharacterState : u32 {
62        /// Is alive.
63        const IsAlive = 1 << 0;
64
65        /// Is downed.
66        const IsDowned = 1 << 1;
67
68        /// Is in combat.
69        const IsInCombat = 1 << 2;
70
71        /// Is on water surface.
72        const IsSwimming = 1 << 3;
73
74        /// Is underwater.
75        const IsUnderwater = 1 << 4;
76
77        /// Is gliding.
78        const IsGliding = 1 << 5;
79
80        /// Is on flying mount.
81        const IsFlying = 1 << 6;
82    }
83}